<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>角色管理-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="__STATIC__/admin/static/css/font.css">
		<link rel="stylesheet" href="__STATIC__/admin/static/css/weadmin.css">
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
	    <script type="text/javascript" src="__STATIC__/admin/static/js/jquery3.2.1.min.js"></script>
	</head>

	<body>
		<div class="weadmin-body">
			<form action="" method="post" class="layui-form">
				<div class="layui-form-item">
					<label for="name" class="layui-form-label">
                        <span class="we-red">*</span>权限名
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="name" name="name" required="" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="name" class="layui-form-label">
                        <span class="we-red">*</span>父级
                    </label>
					<div class="layui-input-inline">
						<select name="parent" required="" lay-verify="required">
							<option value="">请选择权限父级</option>
							<option value="0">顶级</option>
							{volist name='info' id='v1'}
								{if condition="$v1['parent_id'] eq 0"}
									<option value="{$v1['mod_id']}">{$v1['title']}</option>
									{volist name='info' id='v2'}
										{if condition="$v2['parent_id'] eq $v1['mod_id']"}
										<option value="{$v2['mod_id']}">|------{$v2['title']}</option>
											{volist name='info' id='v3'}
												{if condition="$v3['parent_id'] eq $v2['mod_id']"}
													<option value="" disabled="true">|------------{$v3['title']}</option>
												{/if}
											{/volist}
										{/if}
									{/volist}
								{/if}
							{/volist}
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<label for="ctl" class="layui-form-label">
                        控制器名
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="name" name="ctl" required="" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="ctl" class="layui-form-label">
                        是否可见
                    </label>
					<div class="layui-input-inline">
						<input type="radio" name="visible" value="1" title="可见" checked>
						<input type="radio" name="visible" value="0" title="不可见">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"></label>
					<button class="layui-btn" lay-submit="" lay-filter="add">增加</button>
				</div>
			</form>
		</div>
		<script src="__STATIC__/admin/lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript">
			layui.extend({
				admin: '{/}__STATIC__/admin/static/js/admin'
			});
			layui.use(['form', 'layer', 'admin'], function() {
				var form = layui.form,
					admin = layui.admin,
					layer = layui.layer;

				form.on('select',function(data){
					if(data.value!=0){
						$("input[name='ctl']").prop('name','act');
						$("input[name='act']").parent().prev().html("方法名");
					}else{
						$("input[name='act']").prop('name','ctl');
						$("input[name='ctl']").parent().prev().html("控制器名");
					}
				})

				//监听提交
				form.on('submit(add)', function(data) {
					$.ajax({
		                type: 'POST',
		                url: "{:url('admin/rule/add')}",
		                data:$('form').serialize(),
		                traditional:true,
		                success: function(data){
		                    if(data.code==1){
		                        layer.msg(data.msg,{icon:1,time:1000},function(){
		                            parent.location.reload();
		                            parent.layer.close();
		                        });
		                    }else{
		                        layer.msg(data.msg,{icon:2,time:1000},function(){

		                        });
		                    }
		                }
		            });
		            return false;
				});

			});
		</script>
	</body>

</html>